/*__________________________________________ajax请求填充表格数据_______________________________________________________*/
var dataGridData;
function fillDataGrid(){
	$.ajax({
		type:"get",
		url : '../resource/query?temp='+Math.random(),
		dataType:"json",
		async:false,
		success:function(data){
			dataGridData=data.data;
		}
			
	})
}
	
	fillDataGrid();

var treeGrid;
	
	//treeGrid加载表格
		treeGrid = $('#treeGrid').treegrid({
			data:dataGridData,
			//url : '../resource/query?temp='+Math.random(),
			idField : 'id',
			treeField : 'name',
			parentField : 'pId',
			fit : true,
			fitColumns : false,
			border : false,
			method:"get",
			
			columns : [ [	{
				field : 'id',
				title : '编号',
				width : 80,
				align:'left'
			},  {
				field : 'name',
				title : '资源名称',
				width : 200,
				align:'left'
			}, {
				field : 'url',
				title : '资源路径',
				width : 230,
				align:'left'
			}, {
				field : 'resourcetype',
				title : '资源类型',
				width : 80,
				align:'left',
				formatter:function(value,row){
					return commomFun.resourceStatusStr(row.resourcetype);
				}
			}, {
				field : 'cstate',
				title : '状态',
				width : 80,
				align:'left',
				formatter : function(value, row, index) {
					switch (value) {
					case 0:
						return '有效';
					case 1:
						return '无效';
					}
				}	
				
			}, {
				field : 'pId',
				title : '上级资源ID',
				width : 100,
				hidden : true,
				align:'left'
			},{
				field : 'action',
				title : '操作',
				width : 200,
				formatter:function(value,row){
					var str="";
					 str += '<div class="autoBoxTwo"><span class="mynewBtn" onclick=editResource("'+row.id+'")>编辑</span>'+'<span class="mynewBtn col" onclick=delete_res("'+row.id+'")>删除</span></div>';
					return str;
				}
				
			} ] ]
			
			
		});

	//编辑
		function editResource(id){
			
			layer.open({
				type: 2,
				title: ['编辑资源','background-color:#6d6e72; color:#fff;font-size:14px;'],
				shadeClose: true,
				shade: [0.9,'#cfcfcf'],
				area: ['500px', '400px'],  
				content: ['../ak/editResource.html?id='+id],// iframe的url，no代表不显示滚动条
				end:function(){
					
					//$('#treeGrid').treegrid("reload");
					location.reload();
				}
					
			});
		}

/*__________________________________________添加_______________________________________________________*/
$(".add").click(function(){
				layer.open({
					type: 2,
					title: ['添加资源','background-color:#6d6e72; color:#fff;font-size:14px;'],
					shadeClose: true,
					shade: [0.9,'#cfcfcf'],
					area: ['500px', '400px'],  
					content: ['../ak/addResource.html'],// iframe的url，no代表不显示滚动条
					end:function(){
						//getAjax();
						location.reload();
					}
						
				});
			})

/*__________________________________________删除_______________________________________________________*/

	function delete_res(id){
	var obj={};
	 obj.id=parseInt(id);
	//询问框
	layer.confirm('确认关闭该条资源？', {
			title:['温馨提示','background-color:#6d6e72;color:#fff;font-size:14px;'],
			shade: [0.9,'#cfcfcf'],
		   	btn: ['确定','取消'] //按钮
		}, function(){
			layer.msg('删除中...', {icon: 16,shade: 0.01});
			$.ajax({
				type:"post",
				url : '../resource/delete?temp='+Math.random(),
				async:true,
				dataType:"json",
				contentType:'application/json;charset=utf-8',
				data:JSON.stringify(obj),
				success:function(data){
					//console.log(data)
					if(data.status=="1001"){
						layer.msg(data.message, {icon: 1},function(){
							//getAjax();
							location.reload();
						});
					}else{
						layer.msg(data.message, {icon: 2});
					}
				}			
			});		
			
		}, function(){
			
		});	
	}

	
	
	



